--[[   --]]
ardb.call("del", "myhash")
local s = ardb.call("hmset", "myhash", "f0", "v0", "f1", "v1")
ardb.assert2(s["ok"] == "OK", s)
s = ardb.call("hmset2", "myhash", "f2", "v2", "f3", "v3")
ardb.assert2(s["ok"] == "OK", s)
local vs = ardb.call("hgetall", "myhash")
ardb.assert2(vs[1] == "f0", vs)
ardb.assert2(vs[2] == "v0", vs)
ardb.assert2(vs[3] == "f1", vs)
ardb.assert2(vs[4] == "v1", vs)
ardb.assert2(vs[5] == "f2", vs)
ardb.assert2(vs[6] == "v2", vs)
ardb.assert2(vs[7] == "f3", vs)
ardb.assert2(vs[8] == "v3", vs)
s = ardb.call("hlen", "myhash")
ardb.assert2(s == 4, vs)
vs = ardb.call("hkeys", "myhash")
ardb.assert2(vs[1] == "f0", vs)
ardb.assert2(vs[2] == "f1", vs)
ardb.assert2(vs[3] == "f2", vs)
ardb.assert2(vs[4] == "f3", vs)
vs = ardb.call("hvals", "myhash")
ardb.assert2(vs[1] == "v0", vs)
ardb.assert2(vs[2] == "v1", vs)
ardb.assert2(vs[3] == "v2", vs)
ardb.assert2(vs[4] == "v3", vs)
vs = ardb.call("hmget", "myhash", "f2", "f3", "f4")
ardb.assert2(vs[1] == "v2", vs)
ardb.assert2(vs[2] == "v3", vs)
ardb.assert2(vs[3] == false, vs)
s = ardb.call("hdel", "myhash", "f0", "f00")
ardb.assert2(s == 1, s)
s = ardb.call("hdel2", "myhash", "f1", "f01")
ardb.assert2(s["ok"] == "OK", s)
vs = ardb.call("hkeys", "myhash")
ardb.assert2(vs[1] == "f2", vs)
ardb.assert2(vs[2] == "f3", vs)

ardb.call("del", "myhash")
s = ardb.call("hset", "myhash", "f0", "v100")
ardb.assert2(s == 1, s)
s = ardb.call("hset", "myhash", "f0", "v101")
ardb.assert2(s == 0, s)
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "v101", s)
s = ardb.call("hsetnx", "myhash", "f0", "v102")
ardb.assert2(s == 0, s)
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "v101", s)
s = ardb.call("hsetnx", "myhash", "f1", "v102")
ardb.assert2(s == 1, s)
s = ardb.call("hget", "myhash", "f1")
ardb.assert2(s == "v102", s)

ardb.call("del", "myhash")
s = ardb.call("hset2", "myhash", "f0", "v100")
ardb.assert2(s["ok"] == "OK", s)
s = ardb.call("hset2", "myhash", "f0", "v101")
ardb.assert2(s["ok"] == "OK", s)
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "v101", s)
s = ardb.call("hsetnx2", "myhash", "f0", "v102")
ardb.assert2(s["ok"] == "OK", s)
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "v101", s)
s = ardb.call("hsetnx2", "myhash", "f1", "v102")
ardb.assert2(s["ok"] == "OK", s)
s = ardb.call("hget", "myhash", "f1")
ardb.assert2(s == "v102", s)

ardb.call("del", "myhash")
s = ardb.call("hincrby", "myhash", "f0", "7")
ardb.assert2(s == 7, s)
s = ardb.call("hincrby", "myhash", "f0", "3")
ardb.assert2(s == 10, s)
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "10", s)
local s1 = ardb.call("hincrby2", "myhash", "f0", "11")
local s2 = ardb.call("hincrby2", "myhash", "f0", "21")
if ardb.is_merge_supported() then
	ardb.assert2(s1["ok"] == "OK", s)
	ardb.assert2(s2["ok"] == "OK", s)
else
	ardb.assert2(s1 == 21, s)
	ardb.assert2(s2 == 42, s)
end
s = ardb.call("hget", "myhash", "f0")
ardb.assert2(s == "42", s)
ardb.call("del", "myhash")
if ardb.is_merge_supported() then
    s = ardb.call("hincrby2", "myhash", "f1", "11")
    ardb.assert2(s["ok"] == "OK", s)
    s = ardb.call("hincrby2", "myhash", "f1", "21")
    ardb.assert2(s["ok"] == "OK", s)
    s = ardb.call("hget", "myhash", "f1")
    ardb.assert2(s == "32", s)
end
